﻿using B.S.BasicData.Api.Write.Application.Command.Account;
using B.S.BasicData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Api.Write.Controllers
{
    /// <summary>
    /// 账号控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AccountController : ControllerBase
    {
        private readonly IMediator mediator; //中介者组件
        private readonly ILogger<AccountController> logger;

        public AccountController(IMediator mediator,ILogger<AccountController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 创建用户的接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> CreateAccount(CreateAccountCommand request)
        {
            logger.LogInformation("这是添加日志");
            return mediator.Send(request);
        }
        /// <summary>
        /// 更新用户的接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ApiResult<int>> UpdateAccount(UpdateAccountCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 逻辑删除用户的接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ApiResult<int>> DelAccount(DelAccountCommand request)
        {
            
            return mediator.Send(request);
        }
    }
}
